home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / PowerPlant / Gadgets / CGadgetsDoc.cp < prev    next >
Text File  |  1996-03-19  |  6KB  |  261 lines

  1. // CGadgetsDoc.cp -- Document methods
  2. // Created 3/19/96 12:49 PM by AppMaker
  3.  
  4. #include "CGadgetsDoc.h"
  5.  
  6. #include "CGadgetsData.h"
  7. #include "CButtons.h"
  8. #include "CTabbedPanel.h"
  9. #include "CSliders.h"
  10. #include "CProgressBars.h"
  11. #include "CPallette.h"
  12. #include "CmdCodes.h"
  13. #include "CAboutDialog.h"
  14.  
  15. #include <LFile.h>
  16. #include <LPlaceHolder.h>
  17. #include <LPrintout.h>
  18. #include <LWindow.h>
  19. #include <UWindows.h>
  20. #include <String_Utils.h>
  21.  
  22. const ResIDT    prto_PrintView        = 201;
  23. const ResIDT    STRx_Untitled        = 128;
  24.  
  25. // ---------------------------------------------------------------------------
  26. //        • CGadgetsDoc
  27. // ---------------------------------------------------------------------------
  28.  
  29. CGadgetsDoc::CGadgetsDoc(
  30.     LCommander    *inSuper)
  31.         : LSingleDoc(inSuper)
  32. {
  33.     mData = new CGadgetsData();
  34. }
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        • ~CGadgetsDoc
  38. // ---------------------------------------------------------------------------
  39. //    Destructor
  40. //
  41.  
  42. CGadgetsDoc::~CGadgetsDoc()
  43. {
  44.     delete mData;
  45. }
  46.  
  47. //----------
  48. void
  49. CGadgetsDoc::newFile()
  50. {
  51.     mData->newData();
  52.  
  53.     MakeWindows();
  54.  
  55.     NameNewDoc();        // Set name of untitled window
  56. }
  57.  
  58. //----------
  59. void
  60. CGadgetsDoc::openFile(
  61.     FSSpec        *inFileSpec)
  62. {
  63.     mData->openData (inFileSpec);
  64.  
  65.     MakeWindows();
  66.  
  67.     if (mWindow != nil) {
  68.         mWindow->SetDescriptor (inFileSpec->name);
  69.     }
  70.     mIsSpecified = true;
  71. }
  72.  
  73. // ---------------------------------------------------------------------------
  74. //        • MakeWindows
  75. // ---------------------------------------------------------------------------
  76.  
  77. void
  78. CGadgetsDoc::MakeWindows()
  79. {
  80.     mButtons = CButtons::CreateButtons(this, mData);
  81.     mTabbedPanel = CTabbedPanel::CreateTabbedPanel(this, mData);
  82.     mSliders = CSliders::CreateSliders(this, mData);
  83.     mProgressBars = CProgressBars::CreateProgressBars(this, mData);
  84.     mPallette = CPallette::CreatePallette(this, mData);
  85.  
  86.     mWindow = mButtons;
  87. }
  88.  
  89. // ---------------------------------------------------------------------------
  90. //        • NameNewDoc
  91. // ---------------------------------------------------------------------------
  92. //    Name a new, untitled document window
  93. //
  94. //    Untitled windows start with "untitled", then "untitled 1",
  95. //    "untitled 2", etc. Old numbers are reused, so there won't be
  96. //    gaps in the numbering.
  97. //
  98. //    This routine uses a STR# resource to store the "untitled" string,
  99. //    which can be localized to different languages. The first string
  100. //    is "untitled" and the second is "untitled " (trailing space),
  101. //    which is used when appending a number to the name.
  102.  
  103. void
  104. CGadgetsDoc::NameNewDoc()
  105. {
  106.         // Start with the default name("untitled")
  107.     Str255    name;
  108.     ::GetIndString(name, STRx_Untitled, 1);
  109.  
  110.     long    num = 0;
  111.     while (UWindows::FindNamedWindow(name) != nil) {
  112.  
  113.             // An existing window has the current name
  114.             // Increment counter and try again
  115.  
  116.         ::GetIndString(name, STRx_Untitled, 2);
  117.         num++;
  118.         Str15    numStr;
  119.         ::NumToString(num, numStr);
  120.         ConcatPStr(name, numStr);
  121.     }
  122.  
  123.     mWindow->SetDescriptor(name);        // Finally, set window title
  124. }
  125.  
  126. // ---------------------------------------------------------------------------
  127. //        • IsModified
  128. // ---------------------------------------------------------------------------
  129. //    Return whether the Document has changed since the last save
  130.  
  131. Boolean
  132. CGadgetsDoc::IsModified()
  133. {
  134.     mIsModified = mData->IsDirty();
  135.  
  136.     return mIsModified;
  137. }
  138.  
  139. // ---------------------------------------------------------------------------
  140. //        • DoAESave
  141. // ---------------------------------------------------------------------------
  142. //    Save Document in the specified file with the specified file type
  143. //
  144. //    If file type is fileType_Default, use the normal file type for
  145. //    this document
  146.  
  147. void
  148. CGadgetsDoc::DoAESave(
  149.     FSSpec    &inFileSpec,
  150.     OSType    inFileType)
  151. {
  152.     mData->DoSaveAs(&inFileSpec);                // Write out data
  153.                                         // Change window name
  154.     mWindow->SetDescriptor(inFileSpec.name);
  155. }
  156.  
  157. //----------
  158. void
  159. CGadgetsDoc::DoSave()
  160. {
  161.     mData->DoSave();
  162. }
  163.  
  164. //----------
  165. void
  166. CGadgetsDoc::DoRevert()
  167. {
  168.     mData->DoRevert();
  169. }
  170.  
  171. // ---------------------------------------------------------------------------
  172. //        • DoPrint
  173. // ---------------------------------------------------------------------------
  174. //    Print the contents of the Document
  175.  
  176. void
  177. CGadgetsDoc::DoPrint()
  178. {
  179.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  180.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  181.                                     thePrintout->FindPaneByID('TBox');
  182. //!    textPlace->InstallOccupant(mTextView, atNone);
  183.  
  184.  
  185.     thePrintout->DoPrintJob();
  186.     delete thePrintout;
  187. }
  188.  
  189. //----------
  190. void
  191. CGadgetsDoc::DoInvokeAbout ()
  192. {
  193. CAboutDialog*    dialog = CAboutDialog::CreateAboutDialog(this);
  194. }
  195.  
  196. //----------
  197. void
  198. CGadgetsDoc::ObeyAboutDialog    (void*    ioParam)
  199. {
  200. CAboutDialog*    dialog = (CAboutDialog *)ioParam;
  201.  
  202. delete dialog;
  203. }
  204.  
  205. //----------
  206. Boolean
  207. CGadgetsDoc::ObeyCommand(
  208.     CommandT    inCommand,
  209.     void        *ioParam)
  210. {
  211.     Boolean        cmdHandled = true;
  212.  
  213.     switch (inCommand) {
  214.  
  215.     // +++ Add cases here for the commands you handle
  216.     //        Remember to add same cases to FindCommandStatus below
  217.     //        to enable/disable the menu items for the commands
  218.  
  219.  
  220.     case cmdInvokeAbout:
  221.         DoInvokeAbout ();
  222.         break;
  223.  
  224.     case cmd_AboutDialog:
  225.         ObeyAboutDialog    (ioParam);
  226.         break;
  227.  
  228.     default:
  229.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  230.         break;
  231.     }
  232.  
  233.     return cmdHandled;
  234. }
  235.  
  236. //----------
  237. void
  238. CGadgetsDoc::FindCommandStatus(
  239.     CommandT    inCommand,
  240.     Boolean        &outEnabled,
  241.     Boolean        &outUsesMark,
  242.     Char16        &outMark,
  243.     Str255        outName)
  244. {
  245.     outUsesMark = false;
  246.  
  247.     switch (inCommand) {
  248.  
  249.     // +++ Add cases here for the commands you handle
  250.  
  251.     case cmdInvokeAbout:
  252.         outEnabled = true;
  253.         break;
  254.  
  255.     default:
  256.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  257.                                             outUsesMark, outMark, outName);
  258.         break;
  259.     }
  260. }
  261.